Skip to content

fix(sql): return planner error for malformed typed literals#21454

Merged
jonahgao merged 2 commits intoapache:mainfrom
officialasishkumar:fix/invalid-time-typed-literal
Apr 11, 2026
Merged

fix(sql): return planner error for malformed typed literals#21454
jonahgao merged 2 commits intoapache:mainfrom
officialasishkumar:fix/invalid-time-typed-literal

Conversation

@officialasishkumar
Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Planning a malformed typed literal such as time 17542368000000000 currently panics in datafusion-sql because the planner assumes every TypedString payload is string-backed and calls into_string().unwrap().

Invalid SQL should surface as a normal planner error rather than aborting the planning path.

What changes are included in this PR?

  • Replace the unwrap() in the SQLExpr::TypedString planning path with explicit validation.
  • Return a planner error when the typed literal payload is not string-backed.
  • Add a regression test covering the invalid TIME typed literal reported in the issue.

Are these changes tested?

  • cargo test -p datafusion-sql

Are there any user-facing changes?

Users now receive a planner error for malformed typed literals instead of a panic.

@github-actions github-actions bot added the sql SQL Planner label Apr 8, 2026
self.convert_data_type_to_field(&data_type)?,
))),
}) => {
let raw_value = value.to_string();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raw_value is only used in the error branch,introducing a redundant string allocation on the happy path.
How about excluding it from the error message?

let value = value.into_string().ok_or_else(|| {
      plan_datafusion_err!("Typed literal requires a string payload")
  })?;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted this to avoid the happy-path allocation in f416e71.

Guard SQL typed-literal planning against non-string payloads instead of panicking on unwrap. Add a regression test for the invalid TIME literal path reported in apache#21431.

Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
@officialasishkumar officialasishkumar force-pushed the fix/invalid-time-typed-literal branch from 799635a to f416e71 Compare April 10, 2026 14:06
Copy link
Copy Markdown
Member

@jonahgao jonahgao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonahgao jonahgao added this pull request to the merge queue Apr 11, 2026
Merged via the queue into apache:main with commit 374806c Apr 11, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sql SQL Planner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

invalid TIME typed literal causes planner panic

3 participants